﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PersonalHealth.Data.IService;
using PersonalHealth.Data.Service;
using PersonalHealth.Data.Model;
using UI.Comm.Common;

namespace z_Test
{
    /// <summary>
    /// UnitTest1 的摘要说明
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        public UnitTest1()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，该上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        //
        // 编写测试时，可以使用以下附加特性:
        //
        // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // 在运行每个测试之前，使用 TestInitialize 来运行代码
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // 在每个测试运行完之后，使用 TestCleanup 来运行代码
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void FindTest()
        {
            {
                IBloodTypeService service = new BloodTypeService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IDepartmentService service = new DepartmentService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IDoctorService service = new DoctorService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IEnterpriseService service = new EnterpriseService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IEnterpriseTypeService service = new EnterpriseTypeService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IMeasure_BGService service = new Measure_BGService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IMeasure_BOService service = new Measure_BOService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IMeasure_BPService service = new Measure_BPService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IMeasure_ECGService service = new Measure_ECGService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IMeasure_TempService service = new Measure_TempService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IMeasureConditionService service = new MeasureConditionService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IMeasureSubTypeService service = new MeasureSubTypeService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IMeasureTypeService service = new MeasureTypeService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IMeasureUserService service = new MeasureUserService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IMessageBoardService service = new MessageBoardService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IMessageService service = new MessageService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IOfficalDataThresholdService service = new OfficalDataThresholdService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IPersonalDataThresholdService service = new PersonalDataThresholdService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IPositionService service = new PositionService();
                var list = service.Find(c => 1 == 1);
            }

            {
                ISexService service = new SexService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IUserService service = new UserService();
                var list = service.Find(c => 1 == 1);
            }

            {
                ITaskService service = new TaskService();
                var list = service.Find(c => 1 == 1);
            }

            {
                IHealthReportService service = new HealthReportService();
                var list = service.Find(c => 1 == 1);
            }

        }

        [TestMethod]
        public void Login1Test()
        {
            IUserService service = new UserService();
            var obj = service.Login("0001", "");

            Assert.IsTrue(obj is Doctor);
        }

        [TestMethod]
        public void Login2Test()
        {
            IUserService service = new UserService();
            var obj = service.Login("0002", "111111");

            Assert.IsTrue(obj is MeasureUser);
        }

        
        [TestMethod]
        public void GetUserMessagesTest()
        {
            IMessageService service = new MessageService();
            int pages,notread;
            var list = service.GetUserMessages(1, 1, 5, out pages, out notread);

            foreach (var i in list)
            {
                Assert.IsTrue(i.FromUser != null);
                Assert.IsTrue(i.ToUser != null);
            }
        }

        [TestMethod]
        public void GetThreshold1()
        {
            IUserService service = new UserService();
            var obj =  service.GetThreshold("BP", 2);

            foreach (var i in obj)
            {
                var max = i.Max;
            }
        }

        [TestMethod]
        public void GetThreshold2()
        {
            IUserService service = new UserService();
            var obj = service.GetThreshold("BO", 2);

            foreach (var i in obj)
            {
                var max = i.Max;
            }
        }

        [TestMethod]
        public void GetThreshold3()
        {
            IUserService service = new UserService();
            var obj = service.GetThreshold("BG", 2);

            foreach (var i in obj)
            {
                var max = i.Max;
            }
        }

        [TestMethod]
        public void GetThreshold4()
        {
            IUserService service = new UserService();
            var obj = service.GetThreshold("Temp", 2);

            foreach (var i in obj)
            {
                var max = i.Max;
            }
        }

        [TestMethod]
        public void SaveEcg1()
        {
            int[] a = new int[1000];
            for (int i = 0; i < 1000; i++)
            {
                a[i] = i % 150 + 50;
            }

            Measure_ECG ecg = new Measure_ECG();
            ecg.UserId = 2;
            ecg.EcgDiagram = Tools.generateEcgDiagram(a, 120);
            DateTime now = DateTime.Now;
            ecg.MeasureTime = ecg.CreateDate = ecg.ModifyDate = now;
            ecg.EcgDiagramUrl = "";
            ecg.EcgValue = "";
            IMeasure_ECGService ser = new Measure_ECGService();
            ser.Add(ecg);
        }

        [TestMethod]
        public void SaveEcg2()
        {
            int[] a = new int[1200];
            for (int i = 0; i < 1200; i++)
            {
                a[i] = 200 - (i % 150 + 50);
            }

            Measure_ECG ecg = new Measure_ECG();
            ecg.UserId = 2;
            ecg.EcgDiagram = Tools.generateEcgDiagram(a, 120);
            DateTime now = DateTime.Now;
            ecg.MeasureTime = ecg.CreateDate = ecg.ModifyDate = now;
            ecg.EcgDiagramUrl = "";
            ecg.EcgValue = "";
            IMeasure_ECGService ser = new Measure_ECGService();
            ser.Add(ecg);
        }
    }
}
